package com.example.springboot.auto;

import com.example.springboot.condition.TestConditionOnClass;
import com.example.springboot.web.JettyWebServer;
import com.example.springboot.web.TomcatWebServer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author: huangjiazhen
 * @create: 2023/1/12 8:57
 * @description:    自动配置类 接口实现类所在的jar包放在主程序的classpath中
 **/
@Configuration
public class WebServerTestAutoConfiguration implements TestAutoConfiguration {

    // SPI的实现类必须携带一个不带参数的构造方法
    public WebServerTestAutoConfiguration() {
    }

    private String value;

    public WebServerTestAutoConfiguration(String value) {
        this.value = value;
    }

    @Bean
    @TestConditionOnClass("org.apache.catalina.startup.Tomcat")
    public TomcatWebServer tomcatWebServer() {
        return new TomcatWebServer();
    }

    @Bean
    @TestConditionOnClass("org.eclipse.jetty.server.Server")
    public JettyWebServer jettyWebServer() {
        return new JettyWebServer();
    }
}
